package cn.lh.controller;

import cn.lh.dto.ProductDto;
import cn.lh.service.IProductService;
import cn.lh.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/product")
@RefreshScope // 动态刷新配置注解
public class ProductController {
    @Autowired
    private IProductService productService;

    @PutMapping
    public JsonResult add(@RequestBody ProductDto productDto) {
        try {
            return productService.add(productDto);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.set(false, "服务器错误，稍后重试");
        }
    }
}
